package com.yonyou.pmclouds.altercategory.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.altercategory.entity.AlterCategoryVO;
import com.yonyou.pmclouds.altercategory.mapper.AlterCategoryMapper;
import com.yonyou.pmclouds.altercategory.rmiitf.AlterCategoryQuery;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.offline.aspect.Offline;
import com.yonyou.pmclouds.offline.entity.OffLineDataKeyConst;
import com.yonyou.pmclouds.offline.entity.OffLineInvocationContext;
import com.yonyou.pmclouds.offline.rmiitf.IOffLineDataQueryService;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;


@Service(version = ApplicationConsts.APPLICATION_VERSION,interfaceClass= AlterCategoryQuery.class)
@Offline(dataFrom = OffLineDataKeyConst.DATA_ALTER_CATEGORY)
public class AlterCategoryQueryImpl implements AlterCategoryQuery, IOffLineDataQueryService {

    @Autowired
    private AlterCategoryMapper mapper;
    @Override
    public AlterCategoryVO[] queryCategoryListInfo(String pkTenant) throws BusinessException {
        try{
            return mapper.getAllAlterCategory(pkTenant);
        }catch (Exception ex) {
            throw new BusinessException();
        }
    }

    @Override
    public Map<String, String> queryNameByIds(String[] ids) throws BusinessException {
        if (ArrayUtils.isEmpty(ids)) return null;
        Map<String, String> categoryMap = new HashMap<>();
        AlterCategoryVO[] vos = mapper.queryByIds(ids);
        if(null != vos){
            for(AlterCategoryVO vo : vos){
                categoryMap.put(vo.getPkAltercategory(), vo.getSname());
            }
        }
        return categoryMap;
    }

    @Override
    public Object queryOffLineData(OffLineInvocationContext invocationContext) throws BusinessException {

        AlterCategoryVO[] alterCategoryVOS = queryCategoryListInfo(invocationContext.getTenantId());
        return alterCategoryVOS;
    }
}
